#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;

#include <string>
#include <vector>
#include <algorithm>

class Solution
{
public:
    string largestNumber(vector<int>& nums)
    {
        vector<string> strs;
        string res;

        for (const auto& e : nums)
            strs.push_back(to_string(e));

        sort(strs.begin(), strs.end(), [](const string& s1, const string& s2)
            {
                return s1 + s2 > s2 + s1;
            });

        for (int i = 0; i < strs.size(); i++)
            res += strs[i];

        if (res.front() == '0') return "0";

        return res;
    }
};

int main()
{
    vector<int> nums = { 3, 30, 34, 5, 9 };

    string res = Solution().largestNumber(nums);

    cout << res << endl;

    return 0;
}
